import requests
import json
import string
import random
import time

#测试数据
data = {}

portReleaseDt_1 = {}

portReleaseRlt_1 = {}
class request_test():
    global data1
    data1 = json.dumps(data)

    def post_requests(self, for_num):
        #测试环境
        token = ''
        url = ''

        for_num = for_num
        status = '1'
        self.portReleaseDt_2 = []
        self.portReleaseRlt_2 = []
        a = []

        while status == '1':
            # if for_num >= 3:
            #     print('+***+*+*+*+*+**++**+**++*+**+*+*+')
            #     break
            i = 0
            num = 999
            while i < for_num:
                portReleaseRlt_0 = {}
                # portReleaseDt_0 = {}
                num += 1
                rltNo = "22462020I460001000" + str(num)
                portReleaseRlt_1.update({"rltNo": rltNo})
                portReleaseRlt_0.update(portReleaseRlt_1)
                self.portReleaseRlt_2.append(portReleaseRlt_0)
                self.portReleaseDt_2.append(portReleaseDt_1)
                i += 1

            data = data1.replace("portReleaseRlt_1", json.dumps(self.portReleaseRlt_2))
            data = data.replace("portReleaseDt_1", json.dumps(self.portReleaseDt_2))

            # print(self.consumDt_2)
            data = data.replace('"[', '[')
            data = data.replace(']"', ']')
            data = data.replace("dclQty_1", json.dumps(for_num))
            data = data.replace("exitQuantity_1", json.dumps(for_num))

            print("=================1===================")
            try:
                headers = {"orgId": "103321", "Content-Type": "application/json", "epToken": "%s" % token}
                response = requests.post(url=url, headers=headers, data=data)
                print("请求信息：\n %s \n%s \n%s" % (url, headers, data))
                print("********************************")
                try:
                    print("=================2===================")
                    status = response.json().get("status")
                    print(response.json())
                except Exception as E:
                    print("获取返回状态失败：%s" % E)
                    print("当前最大支持表体数：%s" % (for_num-1))
                    # return False, response, E
                try:
                    ass_value = response.json()
                except Exception as E:
                    print("当前最大支持表体数：%s" % (for_num-1))
                    # return False, response, E

                if status == "1" and response.json().get("note") == '修改成功！':
                    print(response.json().get("note"))
                elif 'token cather user fail' in str(ass_value):
                    print("当前最大支持表体数：%s" % (for_num-1))
                else:
                    # return False, ass_value, "请求错误"
                    print('++++++++++++++++++++++++++++++')
                    status = 0
                    print(ass_value)
                    print("当前最大支持表体数：%s" % (for_num-1))
            except Exception as E:
                print("当前最大支持表体数：%s" % (for_num-1))
                print(E)
                return False, E, "请求异常"
            for_num += 1
            print(for_num)


request_test().post_requests(1000)
